home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / dopus412-gpl / library / imagery.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  6KB  |  276 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopuslib.h"
  32.  
  33. struct Image *get_image_data(struct DOpusRemember **,int,int,int,struct BitMap *,struct RastPort *);
  34. void drawline(struct RastPort *rp,int,int,int,int);
  35.  
  36. void __asm __saveds DoDoArrow(register __a0 struct RastPort *p,
  37.     register __d0 int x,
  38.     register __d1 int y,
  39.     register __d2 int w,
  40.     register __d3 int h,
  41.     register __d4 int fg,
  42.     register __d5 int bg,
  43.     register __d6 int d)
  44. {
  45.     int x1,y1,x2,y2,x3,y3,x4,y4,xb;
  46.  
  47.     SetAPen(p,bg);
  48.     xb=x+w;
  49.     RectFill(p,x,y,xb-1,y+h-1);
  50.     SetAPen(p,fg);
  51.     switch (d) {
  52.         case 0:
  53.             y1=y+h-2;
  54.             y3=y+1;
  55.             goto sameupdown;
  56.  
  57.         case 1:
  58.             y1=y+1;
  59.             y3=y+h-2;
  60. sameupdown:
  61.             x1=x+2;
  62.             x2=xb-3;
  63.             x3=x+(w/2)-1;
  64.             x4=xb-(w/2);
  65.             y2=y1;
  66.             y4=y3;
  67.             break;
  68.  
  69.         case 2:
  70.             x1=x+1;
  71.             x3=xb-2;
  72.             goto sameleftright;
  73.  
  74.         case 3:
  75.             x1=xb-2;
  76.             x3=x+1;
  77. sameleftright:
  78.             x2=x1;
  79.             y1=y+1;
  80.             y2=y+h-2;
  81.             y3=y+(h/2);
  82.             if (h%2==0) --y3;
  83.             x4=x3;
  84.             y4=y3;
  85.             break;
  86.     }
  87.     drawline(p,x1,y1,x3,y3);
  88.     drawline(p,x2,y2,x4,y4);
  89. }
  90.  
  91. void __asm __saveds DoDrawRadioButton(register __a0 struct RastPort *rp,
  92.     register __d0 int x,
  93.     register __d1 int y,
  94.     register __d2 int w,
  95.     register __d3 int h,
  96.     register __d4 int hi,
  97.     register __d5 int lo)
  98. {
  99.     SetAPen(rp,hi);
  100.     drawline(rp,x,y-1,x+w-3,y-1);
  101.     drawline(rp,x-1,y,x,y);
  102.     drawline(rp,x-2,y+1,x-2,y+h-4);
  103.     drawline(rp,x-1,y+1,x-1,y+h-4);
  104.     drawline(rp,x-1,y+h-3,x,y+h-3);
  105.     SetAPen(rp,lo);
  106.     drawline(rp,x,y+h-2,x+w-3,y+h-2);
  107.     drawline(rp,x+w-3,y+h-3,x+w-2,y+h-3);
  108.     drawline(rp,x+w-1,y+h-4,x+w-1,y+1);
  109.     drawline(rp,x+w-2,y+h-4,x+w-2,y+1);
  110.     drawline(rp,x+w-3,y,x+w-2,y);
  111. }
  112.  
  113. void drawline(rp,x1,y1,x2,y2)
  114. struct RastPort *rp;
  115. int x1,y1,x2,y2;
  116. {
  117.     Move(rp,x1,y1);
  118.     Draw(rp,x2,y2);
  119. }
  120.  
  121. struct Image * __asm __saveds DoGetButtonImage(register __d0 int w,
  122.     register __d1 int h,
  123.     register __d2 int fg,
  124.     register __d3 int bg,
  125.     register __d4 int fpen,
  126.     register __d5 int bpen,
  127.     register __a0 struct DOpusRemember **key)
  128. {
  129.     struct Image *image;
  130.     short a,b,depth;
  131.     struct BitMap tbm;
  132.     struct RastPort trp;
  133.  
  134.     b=(fg>bg)?fg:bg;
  135.     if (fpen>b) b=fpen;
  136.     if (bpen>b) b=bpen;
  137.  
  138.     depth=2; w+=4;
  139.     for (a=0;a<8;a++) if (b&(1<<a)) depth=a+1;
  140.  
  141.     if (!(image=get_image_data(key,w,h,depth,&tbm,&trp))) return(NULL);
  142.  
  143.     SetAPen(&trp,bpen);
  144.     RectFill(&trp,0,0,w-1,h-1);
  145.     DoDrawRadioButton(&trp,2,1,w-4,h,(fpen!=bpen)?bg:fg,(fpen!=bpen)?fg:bg);
  146.     if (w>10 && h>4 && fpen!=bpen) {
  147.         SetAPen(&trp,fpen);
  148.         RectFill(&trp,4,2,w-7,h-3);
  149.         SetAPen(&trp,bpen);
  150.         WritePixel(&trp,4,2);
  151.         WritePixel(&trp,4,h-3);
  152.         WritePixel(&trp,w-7,2);
  153.         WritePixel(&trp,w-7,h-3);
  154.     }
  155.  
  156.     image->LeftEdge=-2;
  157.     image->TopEdge=-1;
  158.     return(image);
  159. }
  160.  
  161. struct Image * __asm __saveds DoGetCheckImage(register __d0 int fg,
  162.     register __d1 int bg,
  163.     register __d2 int pen,
  164.     register __a0 struct DOpusRemember **key)
  165. {
  166.     struct Image *image;
  167.     int a,b,depth;
  168.     struct BitMap tbm;
  169.     struct RastPort trp;
  170.  
  171.     b=(fg>bg)?fg:bg;
  172.     depth=2;
  173.     for (a=0;a<8;a++) if (b&(1<<a)) depth=a+1;
  174.  
  175.     if (!(image=get_image_data(key,13,7,depth,&tbm,&trp))) return(NULL);
  176.  
  177.     SetDrMd(&trp,JAM1);
  178.     SetAPen(&trp,bg);
  179.     RectFill(&trp,0,0,12,6);
  180.     if (pen) {
  181.         SetAPen(&trp,fg);
  182.         BltTemplate((char *)DOpusBase->pdb_check,0,2,&trp,0,0,13,7);
  183.     }
  184.  
  185.     image->LeftEdge=7;
  186.     image->TopEdge=2;
  187.     return(image);
  188. }
  189.  
  190. void __asm __saveds DoDo3DFrame(register __a0 struct RastPort *rp,
  191.     register __d0 int x,
  192.     register __d1 int y,
  193.     register __d2 int w,
  194.     register __d3 int h,
  195.     register __a1 char *title,
  196.     register __d4 int hi,
  197.     register __d5 int lo)
  198. {
  199.     char of,ob;
  200.     int a,l;
  201.  
  202.     of=rp->FgPen; ob=rp->BgPen;
  203.     Do3DBox(rp,x+2,y+1,w-4,h-2,lo,hi);
  204.     Do3DBox(rp,x+4,y+2,w-8,h-4,hi,lo);
  205.     SetAPen(rp,of); SetBPen(rp,ob);
  206.     if (title) {
  207.         a=strlen(title);
  208.         x+=((w-(l=(TextLength(rp,title,a))))/2);
  209.         SetAPen(rp,ob);
  210.         RectFill(rp,
  211.             x-rp->Font->tf_XSize/2,y+2-rp->Font->tf_Baseline,
  212.             x+l+rp->Font->tf_XSize/2,y+2-rp->Font->tf_Baseline+rp->Font->tf_YSize);
  213.         SetAPen(rp,of);
  214.         Move(rp,x,y+2); Text(rp,title,a);
  215.     }
  216. }
  217.  
  218. extern USHORT __chip glass_image1[];
  219. extern USHORT __chip glass_image2[];
  220.  
  221. void __asm __saveds DoDoGlassImage(register __a0 struct RastPort *rp,
  222.     register __a1 struct Gadget *gadget,
  223.     register __d0 int shine,
  224.     register __d1 int shadow,
  225.     register __d2 int type)
  226. {
  227.     int x,y;
  228.     char op,om;
  229.  
  230.     om=rp->DrawMode; op=rp->FgPen;
  231.     SetDrMd(rp,JAM1);
  232.  
  233.     if (type==0) {
  234.         x=gadget->LeftEdge+((gadget->Width-16)/2);
  235.         y=gadget->TopEdge+((gadget->Height-8)/2);
  236.  
  237.         SetAPen(rp,shine);
  238.         BltTemplate((char *)glass_image2,0,2,rp,x,y,16,8);
  239.         SetAPen(rp,shadow);
  240.         BltTemplate((char *)glass_image1,0,2,rp,x,y,16,8);
  241.     }
  242.  
  243.     SetAPen(rp,op);
  244.     SetDrMd(rp,om);
  245. }
  246.  
  247. struct Image *get_image_data(key,width,height,depth,bm,rp)
  248. struct DOpusRemember **key;
  249. int width,height,depth;
  250. struct BitMap *bm;
  251. struct RastPort *rp;
  252. {
  253.     struct Image *image;
  254.     USHORT *data;
  255.     short a,words;
  256.  
  257.     words=(width+15)/16;
  258.  
  259.     if (!(image=LAllocRemember(key,sizeof(struct Image),MEMF_CLEAR)) ||
  260.         !(data=LAllocRemember(key,words*2*height*depth,MEMF_CHIP|MEMF_CLEAR)))
  261.         return(NULL);
  262.  
  263.     InitBitMap(bm,depth,width,height);
  264.     for (a=0;a<depth;a++) bm->Planes[a]=(PLANEPTR)&data[words*height*a];
  265.     InitRastPort(rp);
  266.     rp->BitMap=bm;
  267.  
  268.     image->Width=width;
  269.     image->Height=height;
  270.     image->Depth=depth;
  271.     image->ImageData=data;
  272.     image->PlanePick=(1<<depth)-1;
  273.  
  274.     return(image);
  275. }
  276.